using FreeSql.DataAnnotations;

namespace SumerCoreDevOps.Domain.Entities;

/// <summary>
/// 角色-权限关联表
/// </summary>
[Table(Name = "role_permissions")]
[Index("idx_role_permission", "RoleId,PermissionId", true)] // 联合唯一索引
public class RolePermission
{
    /// <summary>
    /// 角色 ID（复合主键之一）
    /// </summary>
    [Column(IsPrimary = true, IsNullable = false)]
    public long RoleId { get; set; }

    /// <summary>
    /// 权限 ID（复合主键之一）
    /// </summary>
    [Column(IsPrimary = true, IsNullable = false)]
    public long PermissionId { get; set; }

    /// <summary>
    /// 分配时间
    /// </summary>
    [Column(IsNullable = false)]
    public DateTime AssignedAt { get; set; } = DateTime.UtcNow;

    /// <summary>
    /// 分配者
    /// </summary>
    [Column(StringLength = 100)]
    public string? AssignedBy { get; set; }

    /// <summary>
    /// 关联的角色
    /// </summary>
    [Navigate(nameof(RoleId))]
    public Role? Role { get; set; }

    /// <summary>
    /// 关联的权限
    /// </summary>
    [Navigate(nameof(PermissionId))]
    public Permission? Permission { get; set; }
}
